package com.example.xunua_zhinengjiaotong;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.example.xunua_zhinengjiaotong.Dialog.CarSpeedDialog;
import com.example.xunua_zhinengjiaotong.Dialog.CarSpeedDialog2;
import com.example.xunua_zhinengjiaotong.Dialog.CarSpeedDialog3;
import com.example.xunua_zhinengjiaotong.Dialog.CarSpeedDialog4;
import com.example.xunua_zhinengjiaotong.utils.MyApp;

public class TrolleyActivity extends AppCompatActivity implements View.OnClickListener{
    private RelativeLayout rl_sudu,rl_xiaochejilu,rl_line2,rl_line3,rl_line4;
    private ImageView img_back;
    private MyApp myApp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trolley);
        initView();
    }

    private void initView() {
        myApp= (MyApp) getApplication();
        rl_sudu=findViewById(R.id.trolley_rl_sudu);
        rl_sudu.setOnClickListener(this);
        img_back=findViewById(R.id.trolley_img_back);
        img_back.setOnClickListener(this);
        rl_xiaochejilu=findViewById(R.id.trolley_rl_xiaochejilu);
        rl_xiaochejilu.setOnClickListener(this);
        rl_line2=findViewById(R.id.trolley_carline2);
        rl_line3=findViewById(R.id.trolley_carline3);
        rl_line4=findViewById(R.id.trolley_carline4);
        rl_line2.setOnClickListener(this);
        rl_line3.setOnClickListener(this);
        rl_line4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.trolley_rl_sudu://小车速度
                CarSpeedDialog carSpeedDialog=new CarSpeedDialog(TrolleyActivity.this, new CarSpeedDialog.DataListener() {
                    @Override
                    public void sendData(String s) {
                        Toast.makeText(TrolleyActivity.this, "s:"+s, Toast.LENGTH_SHORT).show();
                    }
                },myApp);
                carSpeedDialog.show();
//                方式二
//                WindowManager.LayoutParams wParams=this.getWindow().getAttributes();
//                WindowManager.LayoutParams params=this.getWindow().getAttributes();
//                params.width= (int) (wParams.width*0.6);
//                params.height= (int) (wParams.height*0.6);
//                carSpeedDialog.getWindow().setAttributes(params);

//                方式一
//                WindowManager.LayoutParams params=carSpeedDialog.getWindow().getAttributes();
//                params.width=300;
//                params.width=400;
//                carSpeedDialog.getWindow().setAttributes(params);
                break;
            case R.id.trolley_img_back:
                finish();
                break;
            case R.id.trolley_rl_xiaochejilu:  //小车记录
                startActivity(new Intent(TrolleyActivity.this,Trolley_RecordActivity.class));
                break;
            case R.id.trolley_carline2://小车位置
                //接口测试异常。未做
                CarSpeedDialog2 carSpeedDialog2=new CarSpeedDialog2(TrolleyActivity.this);
                carSpeedDialog2.show();
                break;
            case R.id.trolley_carline3://小车余额
                CarSpeedDialog3 carSpeedDialog3=new CarSpeedDialog3(TrolleyActivity.this,myApp);
                carSpeedDialog3.show();
                break;
            case R.id.trolley_carline4://小车动作
                CarSpeedDialog4 carSpeedDialog4=new CarSpeedDialog4(TrolleyActivity.this,myApp);
                carSpeedDialog4.show();
                break;
        }
    }
    @Override
    public void onBackPressed() {
        // super.onBackPressed();
    }
}
